#ifndef VXGRAPHICSVIEW_H
#define VXGRAPHICSVIEW_H

#include <QtGui>
#include <QGraphicsView>
#include "vxpinbutton.h"
#include "vxcrosshair.h"
#include "vxdockselector.h"
#include "vxzoomslider.h"
#include "../Controllers/vxzoomcontroller.h"
#include "../Controllers/vxhandcontroller.h"

class VxRuller;

class VxGraphicsView : public QGraphicsView
{

	Q_OBJECT

public:

	VxGraphicsView(QGraphicsScene *scene, QWidget *parent = 0);
	~VxGraphicsView();

	void resizeEvent(QResizeEvent *event);

	VxZoomController * zoomController() const {
		return _zoomController;
	}


	QGraphicsProxyWidget * rullers() const {
		return _rullers;
	}

	void paintEvent(QPaintEvent *event);

private:
	QGraphicsProxyWidget * _rullers;

	bool _mpress;
	QWidget * _zoom;
	QPoint _nullPoint;
	QPoint _lastPoint;

	VxZoomController * _zoomController;
	VxHandController * _handController;

	void _init();
	void _createControls();
	QDialog * _createDialog(const QString &windowTitle) const;

signals:
	void beforeViewPaint();


};



class VxProxyWidget : public QGraphicsProxyWidget
{
	Q_OBJECT

	Q_PROPERTY(QPoint viewPos READ getViewPos WRITE setViewPos)

public:
	VxProxyWidget(VxGraphicsView * view, QGraphicsItem * parent=0);

	~VxProxyWidget();

	void initFloating();

	void setViewPos(int x, int y);

	void setViewPos(QPoint p);


	QPoint getViewPos();

	QGraphicsView * getView(){	return _view; };

	QPropertyAnimation * animation() {	return _animation; };

protected:
	QGraphicsView * _view;

	bool _pressed;

	void mousePressEvent(QGraphicsSceneMouseEvent *event);


	void mouseMoveEvent(QGraphicsSceneMouseEvent *event);


	void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

	QPoint validatePos(QPoint p);

private:
	QPoint _viewp;
	QPropertyAnimation * _animation;
	QTime time;

	bool _isValidatePos(QPointF p);

private slots:
	void _beforeViewPaint();
	void _mouseMomentum(QPoint delta, qreal momentum);
	void _valueChanged(QVariant value);
	void _cancelPressed();

public slots:
	void cancelAnimation();

signals:
	void breakdownMomentum(int);
	void breakdownEffort(QPoint deltap);
	void movement(int, int);
};



#endif // VXGRAPHICSVIEW_H

